//
//  XS_MineInfoIndustryCell.swift
//  XueDao
//
//  Created by Mac on 2020/12/26.
//

import UIKit

class XS_MineInfoIndustryCell: UITableViewCell {

    @IBOutlet weak var collectionView: UICollectionView!
    
    var _industryList : [String] = []
    public var industryList : [String]{
        set{
            _industryList = newValue
            //设置数据
            collectionView.reloadData()
        }
        get{
            return _industryList
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        collectionView.register(UINib.init(nibName: "XS_MineInfoIndustryItemCell", bundle: Bundle.main), forCellWithReuseIdentifier: "XS_MineInfoIndustryItemCell")
        collectionView.delegate = self
        collectionView.dataSource = self
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

extension XS_MineInfoIndustryCell : UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return industryList.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "XS_MineInfoIndustryItemCell", for: indexPath) as! XS_MineInfoIndustryItemCell
        if indexPath.item < industryList.count {
            cell.titleLabel.text = industryList[indexPath.item]
        }
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize.init(width: XS_MineInfoIndustryItemCell.getCellWidth(title: industryList[indexPath.item]), height: 32)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets.init(top: 8, left: 16, bottom: 8, right: 8)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 8
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 8
    }
}
